<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8"/>
    <meta http-equiv="X-UA-Compatible" content="IE=Edge,chrome=1"/>
    <!--<meta name="viewport" content="width=device-width, initial-scale=1, minimum-scale=1.0, maximum-scale=1.0" />-->
    <title>新增留言</title>
    <link rel="stylesheet" th:href="@{/static/css/default/jquery.mobile-1.4.2.min.css}" />
    <script th:src="@{/static/js/default/jquery-2.0.3.min.js}"></script>
    <script th:src="@{/static/js/default/jquery.mobile-1.4.2.min.js}"></script>

    <style type="text/css">

        #title_bt {
            color:#02534a;
            font-family:Microsoft YaHei;
            font-size:20px;
        }
        .title_font{
            border-bottom-width:1px;
            margin:1px;
            color:black;
            font-family:Microsoft YaHei;
        }
        .zhanghu_num{
            border-bottom-width:1px;
            font-family:Microsoft YaHei;
            margin-left:10px;
            margin-right:10px;
            padding-top:7px;
            padding-bottom:7px;
        }
        #zhanghusub_bt {
            background-color:#02534a;
            color:white;
            margin-top:30px;
            margin-left:10px;
            margin-right:10px;
        }

        .ui-grid-a .ui-block-a {
            width: 30%;
        }
        .ui-grid-a .ui-block-b {
            width: 70%;
        }

        .ui-body-a,.ui-page-theme-a .ui-body-inherit,html .ui-bar-a .ui-body-inherit,html .ui-body-a .ui-body-inherit,html body .ui-group-theme-a .ui-body-inherit,html .ui-panel-page-container-a{background-color:#fff;border-color:rgba(0,0,0,0);color:#333;text-shadow:0 1px 0 #f3f3f3;-webkit-box-shadow: inset 0 1px 3px rgba(0,0,0,0);
            -moz-box-shadow: inset 0 1px 3px rgba(0,0,0,0);
            box-shadow: inset 0 1px 3px rgba(0,0,0,0);
            margin:1px;
            background-color:rgba(0,0,0,0)}


    </style>
    <script type="text/javascript">
        function submitInfo(){
            var parten = /^\s*$/ ;
            var title = $("#leave_title").val();
            var contact = $("#leave_contact").val();
            var content = $("#leave_content").val();
//            var Request = new Object();
            //Request = GetRequest();
//            var openid = Request['openid'];
//            $("#openid").val(openid);

            if(title==""||title==null)
            {
                $("#result").text("请输入留言主题！");
                $( "#confirm" ).popup( "open" );
            }
            else if(parten.test(title))
            {
                $("#result").text("您输入的留言主题全是空格，请重新输入！");
                $( "#confirm" ).popup( "open" );
            }
            else if(title.length>25)
            {
                $("#result").text("留言主题请控制在25个汉字以内！");
                $( "#confirm" ).popup( "open" );
            }
            else if(contact==""||contact==null)
            {
                $("#result").text("请输入手机号！");
                $( "#confirm" ).popup( "open" );
            }
            else if(isNaN(contact)||(contact.length!=11))
            {
                $("#result").text("请确认手机号码为11位纯数字！");
                $( "#confirm" ).popup( "open" );
            }
            else if(content==""||content==null)
            {
                $("#result").text("请输入留言内容！");
                $( "#confirm" ).popup( "open" );
            }
            else if(parten.test(content))
            {
                $("#result").text("您输入的留言内容全是空格，请重新输入！");
                $( "#confirm" ).popup( "open" );
            }
            else if(content.length>128)
            {
                $("#result").text("留言内容请控制在128汉字以内！");
                $( "#confirm" ).popup( "open" );
            }

            var xhr = new XMLHttpRequest();
            var url ="/message/saveMsg";
            var data = JSON.stringify({
                "TITLE":title,"PHONE":contact,"CONTENT":content
            });

            xhr.open("POST", url );
            xhr.setRequestHeader('Content-Type','application/json');
            xhr.onload = function(){
                console.log(xhr.responseText); // 这里要用xhr.respnseText 获取数据，我经常给函数传一个data参数，获取数据，造成错误
                var result = xhr.responseText;
                if(result.code = '000000'){
                    window.location.href="/message/listMsg";
                }
            }
            xhr.send(data);
        }
    </script>
    <!--<script type="text/javascript">
        $(document).ready(function(){
            //isBingding();
        });

        /*function GetRequest()
        {
            var url = location.search;
            url = decodeURI(url);
            var theRequest = new Object();
            if (url.indexOf("?") != -1)
            {
                var str = url.substr(1);
                strs = str.split("&");
                for(var i = 0; i < strs.length; i ++)
                {
                    theRequest[strs[i].split("=")[0]]=unescape(strs[i].split("=")[1]);
                }

            }
            return theRequest;
        }*/

        /*function isBingding() {
            var url_init = location.search;
            var Request = new Object();
            Request = GetRequest();
            var openid;
            openid = Request['openid'];

            if(url_init.indexOf("isSavedFlag") > 0)
            {
                var Request = new Object();
                Request = GetRequest();
                var title,contact,content;
                title = Request['title'];
                contact = Request['contact'];
                content = Request['content'];
                $("#leave_title").val(title);
                $("#leave_contact").val(contact);
                $("#leave_content").val(content);
            }
        };*/


        function submitInfo(){

            var parten = /^\s*$/ ;
            var title = $("#leave_title").val();
            var contact = $("#leave_contact").val();
            var content = $("#leave_content").val();
            var Request = new Object();
            Request = GetRequest();
            var openid = Request['openid'];
            $("#openid").val(openid);

            if(title==""||title==null)
            {
                $("#result").text("请输入留言主题！");
                $( "#confirm" ).popup( "open" );
                return false ;
            }
            else if(parten.test(title))
            {
                $("#result").text("您输入的留言主题全是空格，请重新输入！");
                $( "#confirm" ).popup( "open" );
                return false ;
            }
            else if(title.length>25)
            {
                $("#result").text("留言主题请控制在25个汉字以内！");
                $( "#confirm" ).popup( "open" );
                return false ;
            }
            else if(contact==""||contact==null)
            {
                $("#result").text("请输入手机号！");
                $( "#confirm" ).popup( "open" );
                return false ;
            }
            else if(isNaN(contact)||(contact.length!=11))
            {
                $("#result").text("请确认手机号码为11位纯数字！");
                $( "#confirm" ).popup( "open" );
                return false ;
            }
            else if(content==""||content==null)
            {
                $("#result").text("请输入留言内容！");
                $( "#confirm" ).popup( "open" );
                return false ;
            }
            else if(parten.test(content))
            {
                $("#result").text("您输入的留言内容全是空格，请重新输入！");
                $( "#confirm" ).popup( "open" );
                return false ;
            }
            else if(content.length>128)
            {
                $("#result").text("留言内容请控制在128汉字以内！");
                $( "#confirm" ).popup( "open" );
                return false ;
            }
            return true ;

        }
    </script>
    <script>
        var _hmt = _hmt || [];
        (function() {
            var hm = document.createElement("script");
            hm.src = "//hm.baidu.com/hm.js?2a78cb3724c93e51663ac7016d939898";
            var s = document.getElementsByTagName("script")[0];
            s.parentNode.insertBefore(hm, s);
        })();
    </script> -->
</head>

<body>
<div data-role="page">

    <div data-role="content" id="content_id">
        <form action="javascript:void(0)" method="post" data-ajax="false">
            <input type="hidden" id="openid" name="openid" value="" />
            <h2 id = "title_bt" style="margin-top:3px;margin-bottom:1px">新增留言</h2>
            <div data-role="fieldcontain" class="ui-grid-a zhanghu_num" >
                <div class="ui-block-a">
                    <span style="line-height:40px;">*主 题：</span>
                </div>
                <div class="ui-block-b">
                    <span><input type="text" id="leave_title" class="no registInput" name="title" placeholder="请输入留言主题" /></span>
                </div>
            </div>

            <div data-role="fieldcontain"  class="ui-grid-a zhanghu_num" >
                <div class="ui-block-a">
                    <span style="line-height:40px;">*电话：</span>
                </div>
                <div class="ui-block-b">
                    <span><input type="text" id="leave_contact" class="no registInput" name="phone" placeholder="请输入联系方式" /></span>
                </div>
            </div>
            <div data-role="fieldcontain" class="ui-grid-a zhanghu_num" >
                <div class="ui-block-a">
                    <span style="line-height:40px;">*内容：</span>
                </div>
                <div class="ui-block-b">
                    <span><textarea id="leave_content" cols="40" rows="8" name="contentmsg" placeholder="请输入留言内容"></textarea></span>
                </div>
            </div>

            <div class="ui-input-btn ui-btn ui-corner-all ui-shadow" id = "zhanghusub_bt" onclick="submitInfo();">
                提&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;交
                <input type="submit" data-enhanced="true"  />
            </div>
        </form>
    </div>

    <div data-role="foot" style="margin-left:10px;margin-top:2px;" >
        <p style="margin:2px;margin-top:2px; color: #ff9000;font-size: 3px;">温馨提示：</p>
        <p style="margin-left:12px;margin-top:2px;margin-bottom:2px;margin-right:12px;color: #a1a1a1;font-size: 2px;" >1、*为必填项</p>
        <p style="margin-left:12px;margin-top:2px;margin-bottom:2px;margin-right:12px;color: #a1a1a1;font-size: 2px;" >2、请尽量留下您正确的联系方式，我们的工作人员会尽快联系您</p>
        <p style="margin-left:12px;margin-top:2px;margin-bottom:2px;margin-right:12px;color: red;font-size: 2px;" >3、留言完成后，可通过点击“客户留言”->“留言记录”查看留言回复！</p>
    </div>

    <div align="center" id="confirm" class="ui-content ui-popup  ui-overlay-shadow ui-corner-all" data-role="popup" data-theme="a"  style="background-color:#fff;solid;width:225px;box-shadow:0 0 12px rgba(0, 0, 0, .6);border-width:0px;">
        <p>提示：</p>
        <h3> <span id="result"></span></h3>
        <p></p>
        <div class="ui-grid-a">
            <a id="yes" class="ui-btn ui-corner-all ui-mini ui-btn-a" data-rel="back">确认</a>
        </div>
    </div>

</div>
<script th:src="@{/static/js/default/weixin.js}" ></script>
</body>
</html>
